local julian = fk.CreateSkill {
  name = "lingling__julian",
}

Fk:loadTranslationTable{
  ["lingling__julian"] = "巨敛",
  [":lingling__julian"] = "一名角色回合结束时，若其手牌数小于体力值，你可以令其将一张牌当【无中生有】使用，然后若其手牌数不小于体力值，"..
  "其交给你一张手牌。",

  ["#lingling__julian-invoke"] = "巨敛：是否令 %dest 将一张手牌当【无中生有】使用并交给你一张手牌？",
  ["#lingling__julian_self-invoke"] = "巨敛：是否将一张手牌当【无中生有】使用？",
  ["#lingling__julian-use"] = "巨敛：请将一张手牌当【无中生有】使用",
  ["#lingling__julian-give"] = "巨敛：请交给 %src 一张手牌",
}

julian:addEffect(fk.TurnEnd, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(julian.name) and not target.dead and
      target:getHandcardNum() < target.hp and (#target:getHandlyIds() > 0 or #target:getCardIds("e") > 0) and
      target:canUseTo(Fk:cloneCard("ex_nihilo"), target)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local prompt = "#lingling__julian-invoke::"..target.id
    if target == player then
      prompt = "#lingling__julian_self-invoke"
    end
    if room:askToSkillInvoke(player, {
      skill_name = julian.name,
      prompt = prompt,
    }) then
      event:setCostData(self, {tos = {target}})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:askToUseVirtualCard(target, {
      name = "ex_nihilo",
      skill_name = julian.name,
      prompt = "#lingling__julian-use",
      cancelable = false,
      card_filter = {
        n = 1,
      },
    })
    if target ~= player and not player.dead and not target.dead and
      target:getHandcardNum() >= target.hp and not target:isKongcheng() then
      local cards = room:askToCards(target, {
        min_num = 1,
        max_num = 1,
        include_equip = false,
        skill_name = julian.name,
        prompt = "#lingling__julian-give:"..player.id,
        cancelable = false,
      })
      room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonGive, julian.name, nil, false, target)
    end
  end,
})

return julian
